import fetch from '@system.fetch';
/*
 * Copyright (c) 2021 Huawei Device Co., Maker-IoT-PD.
 * Licensed under the Apache License,Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */



import router from '@system.router';
import storage from '@system.storage';
import http from '@ohos.net.http';
import prompt from '@system.prompt';
var info = null;

export default {
    data: {
        title: "Hello HarmonyOS",
        isHarmonyOS: true,
        phone: '',
        mediate: '',  // 捏合
        mediate_grade: '',  // 手指伸展
        finger: '',  //
        finger_grade: '',
        tremble: '',
        tremble_grade: '',
        myoelectricity: '',
        myoelectricity_grade: '',
        "setArray": [
            {"dir":"/common/images/mine_message.svg"},
            {"value": "意见反馈"},
            {"dir":"/common/images/mine_set.png"},
            {"value": "系统设置"},
            {"dir":"/common/images/mine_quit.png"},
            {"value": "退出登录"},
            {"dir":"/common/images/mine_about.svg"},
            {"value": "关于"},
        ],

        "dirArray": [
            {"dir":"/common/images/mine_message.svg"},
            {"dir":"/common/images/mine_set.png"},
            {"dir":"/common/images/mine_quit.png"},
            {"dir":"/common/images/mine_about.svg"},
        ],
        return_result: {
        },
        types:"Kneading",
        vals11:"-",
        vals12:"-",
        vals13:"-",
    },
    upload(){
        let jsondata;
        fetch.fetch({
            url:"https://console-mock.apipost.cn/mock/c87286cd-16cb-4dc6-9dc0-6707d7641883/chuanshu",
            responseType:"json",
            method:"POST",
            success:(resp)=>
            {
                jsondata = JSON.parse(resp.data);
                this.return_result = jsondata;
                this.vals11 = jsondata.last_update;
                this.vals12 = jsondata.data_Kneading;
                this.vals13 = jsondata.data_kneadlevel;
                prompt.showToast({
                    message: "获取成功",
                    duration: 3000,
                });
                console.info("捏合获取数据成功："+resp.data)
            },
            fail:(resp)=>
            {
                prompt.showToast({
                    message: '数据获取失败',
                    duration: 2000,
                })
                //打印失败原因
                console.info("获取失败")
                console.info("失败原因："+resp.data)
            }
        })
    },
    showDialog(e) {
        this.$element('dragDialog').show()
    },
    setSchedule(e) {
        this.$element('dragDialog').close()
    },

    showhintDialog(e) {
        this.$element('hintDialog').show()
    },
    sethintDialog(e) {
        this.$element('hintDialog').close()
    },
    showeventDialog(e) {
        this.$element('eventDialog').show()
    },
    getList(e) {
        info = e.value
    },


    //    change(e){
    //        prompt.showToast({
    //            message: 'value: ' + e.text + ', lines: ' + e.lines + ', height: ' + e.height,
    //            duration: 3000,
    //        });
    //    },

    switchTitle() {
        let that = this;
        that.title = that.isHarmonyOS ? "Hello World" : "Hello HarmonyOS";
        that.isHarmonyOS = !that.isHarmonyOS;
    },

    onInit(){
        // 从缓存取用户信息，自动登录
        storage.get({
            key: 'id',
            success: data => {
                if(data){
                    this.phone = data
                }
            },
        });

        // 昵称
        storage.get({
            key: 'name',
            success: data => {
                if(data){
                    this.phone = data
                }
            },
        });

        // 从缓存取用户信息，自动登录
        storage.get({
            key: 'id',
            success: data => {
                if(data){
                    this.phone = data
                }
            },
        });

    },
    feedback(){
        router.push ({
            uri:'pages/feedback/feedback', // 指定要跳转的页面
        })
    },
    quit(){
        router.push ({
            uri:'pages/login/login', // 指定要跳转的页面
        })
    }

}